package jumpingnotes.service;

import java.util.List;

import jumpingnotes.model.entity.Activity;
import jumpingnotes.model.entity.Audio;
import jumpingnotes.model.entity.Book;
import jumpingnotes.model.entity.BookComment;
import jumpingnotes.model.entity.BookVersion;
import jumpingnotes.model.entity.Chapter;
import jumpingnotes.model.entity.ChapterVersion;
import jumpingnotes.model.entity.Deploy;
import jumpingnotes.model.entity.ErrorReport;
import jumpingnotes.model.entity.Friend;
import jumpingnotes.model.entity.Group;
import jumpingnotes.model.entity.GroupTopic;
import jumpingnotes.model.entity.GroupTopicComment;
import jumpingnotes.model.entity.Member;
import jumpingnotes.model.entity.MemberExperience;
import jumpingnotes.model.entity.Message;
import jumpingnotes.model.entity.RecordAlbum;
import jumpingnotes.model.entity.RecordTask;
import jumpingnotes.model.entity.Sync;
import jumpingnotes.security.SessionManager;

public class QueryServiceImpl extends AccessServiceImpl implements QueryService
{
	protected SessionManager sessionManager;

	public void setSessionManager(SessionManager sessionManager)
	{
		this.sessionManager = sessionManager;
	}

	public SessionManager getSessionManager()
	{
		return sessionManager;
	}

	// -------------------- query --------------------

	public List<Book> findBookByBookTag(String bookTag, int firstResult, int maxResults)
	{
		return bookDao.findBookByBookTag(bookTag, firstResult, maxResults);
	}

	public List<Member> findMemberByGroupId(int groupId, int firstResult, int maxResults)
	{
		return memberDao.findMemberByGroupId(groupId, firstResult, maxResults);
	}

	public Member findMemberByEmail(String email)
	{
		return memberDao.findMemberByEmail(email);
	}

	public List<Member> findMemberByFriendMemberId(int memberId, int firstResult, int maxResults)
	{
		return memberDao.findMemberByFriendMemberId(memberId, firstResult, maxResults);
	}

	public List<Group> findGroupByMemberId(int memberId)
	{
		return groupDao.findGroupByMemberId(memberId);
	}

	public List<Chapter> findChapterByBookId(int bookId, int firstResult, int maxResults)
	{
		return chapterDao.findChapterByBookId(bookId, firstResult, maxResults);
	}

	public List<Activity> findActivityByMemberId(int memberId, int firstResult, int maxResults)
	{
		return activityDao.findActivityByMemberId(memberId, firstResult, maxResults);
	}

	public List<Book> findFavoriteBookByMemberId(int memberId)
	{
		return bookDao.findFavoriteBookByMemberId(memberId);
	}

	public List<Activity> findActivityByGroupId(int groupId, int firstResult, int maxResults)
	{
		return activityDao.findActivityByGroupId(groupId, firstResult, maxResults);
	}

	public List<GroupTopic> findGroupTopicByGroupId(int groupId, int firstResult, int maxResults)
	{
		return groupTopicDao.findGroupTopicByGroupId(groupId, 0, firstResult, maxResults);
	}

	public List<GroupTopic> findStickyTopicByGroupId(int groupId, int firstResult, int maxResults)
	{
		return groupTopicDao.findGroupTopicByGroupId(groupId, 1, firstResult, maxResults);
	}

	public List<RecordTask> findRecordTaskByRecordAlbumId(int recordAlbumId, int firstResult, int maxResults)
	{
		return recordTaskDao.findRecordTaskByRecordAlbumId(recordAlbumId, firstResult, maxResults);
	}

	public List<BookComment> findBookCommentByBookId(int bookId, int firstResult, int maxResults)
	{
		return bookCommentDao.findBookCommentByBookId(bookId, firstResult, maxResults);
	}

	public List<BookVersion> findValueByBookIdAndProperty(int bookId, String property)
	{
		return bookVersionDao.findValueByBookIdAndProperty(bookId, property);
	}

	public List<ChapterVersion> findValueByChapterIdAndProperty(int chapterId, String property)
	{
		return chapterVersionDao.findValueByChapterIdAndProperty(chapterId, property);
	}

	public List<BookVersion> findBookVersionByBookId(int bookId, int firstResult, int maxResults)
	{
		return bookVersionDao.findBookVersionByBookId(bookId, firstResult, maxResults);
	}

	public List<ChapterVersion> findChapterVersionByChapterId(int chapterId, int firstResult, int maxResults)
	{
		return chapterVersionDao.findChapterVersionByChapterId(chapterId, firstResult, maxResults);
	}

	public List<RecordAlbum> findRecordAlbumByBookId(int bookId, int firstResult, int maxResults)
	{
		return recordAlbumDao.findRecordAlbumByBookId(bookId, firstResult, maxResults);
	}

	public List<RecordTask> findRecordTaskByChapterId(int chapterId, int firstResult, int maxResults)
	{
		return recordTaskDao.findRecordTaskByChapterId(chapterId, firstResult, maxResults);
	}

	public List<RecordAlbum> findRecordAlbumByMemberId(int memberId, int firstResult, int maxResults)
	{
		return recordAlbumDao.findRecordAlbumByMemberId(memberId, firstResult, maxResults);
	}

	public boolean checkRecordTaskUnique(int chapterId, int recordAlbumId)
	{
		return recordTaskDao.checkRecordTaskUnique(chapterId, recordAlbumId);
	}

	public boolean isFriend(int memberId1, int memberId2)
	{
		return friendDao.isFriend(memberId1, memberId2);
	}

	public boolean isMemberInGroup(int memberId, int groupId)
	{
		return groupMemberDao.isMemberInGroup(memberId, groupId);
	}

	public List<MemberExperience> findMemberExperienceByMemberId(int memberId, int firstResult, int maxResults)
	{
		return memberExperienceDao.findMemberExperienceByMemberId(memberId, firstResult, maxResults);
	}

	public List<Friend> findFriendFromByMemberId(int memberId, int firstResult, int maxResults)
	{
		return friendDao.findFriendFromByMemberId(memberId, firstResult, maxResults);
	}

	public List<Friend> findFriendToByMemberId(int memberId, int firstResult, int maxResults)
	{
		return friendDao.findFriendToByMemberId(memberId, firstResult, maxResults);
	}

	public Audio findAudioByUuid(String uuid)
	{
		return audioDao.findAudioByUuid(uuid);
	}

	public Sync findSyncByUuid(String uuid)
	{
		return syncDao.findSyncByUuid(uuid);
	}

	public Deploy findDeployByUuid(String uuid)
	{
		return deployDao.findDeployByUuid(uuid);
	}

	public Chapter findChapterByUuid(String uuid)
	{
		return chapterDao.findChapterByUuid(uuid);
	}
	
	public int countMemberByFavoriteBook(int bookId)
	{
		return memberDao.countMemberByFavoriteBook(bookId);
	}

	public List<Book> findBookLatest(int firstResult, int maxResults)
	{
		return bookDao.findBookLatest(firstResult, maxResults);
	}

	public List<Book> findBookPlayTop(int firstResult, int maxResults)
	{
		return bookDao.findBookPlayTop(firstResult, maxResults);
	}

	public List<Book> findBookRateTop(int firstResult, int maxResults)
	{
		return bookDao.findBookRateTop(firstResult, maxResults);
	}

	public List<Book> findBookRecommend(int firstResult, int maxResults)
	{
		return bookDao.findBookRecommend(firstResult, maxResults);
	}
	
	public List<Deploy> findDeployByAudioId(int audioId, int firstResult, int maxResults)
	{
		return deployDao.findDeployByAudioId(audioId, firstResult, maxResults);
	}
	
	public List<Message> findMessageByMemberId(int memberId, int firstResult, int maxResults)
	{
		return messageDao.findMessageByMemberId(memberId, firstResult, maxResults);
	}
	
	public List<Activity> findActivityPlaying(int firstResult, int maxResults)
	{
		return activityDao.findActivityPlaying(firstResult, maxResults);
	}
	
	public List<Activity> findActivityRecording(int firstResult, int maxResults)
	{
		return activityDao.findActivityRecording(firstResult, maxResults);
	}
	
	public List<Activity> findActivityByFriendMemberId(int memberId, int firstResult, int maxResults)
	{
		return activityDao.findActivityByFriendMemberId(memberId, firstResult, maxResults);
	}

	public List<Activity> findActivityByAllGroupMemberId(int memberId, int firstResult, int maxResults)
	{
		return activityDao.findActivityByAllGroupMemberId(memberId, firstResult, maxResults);
	}
	
	public List<GroupTopicComment> findGroupTopicCommentByGroupTopicId(int groupTopicId, int firstResult, int maxResults)
	{
		return groupTopicCommentDao.findGroupTopicCommentByGroupTopicId(groupTopicId, firstResult, maxResults);
	}
	
	// -------------------- index --------------------

	public void indexBook()
	{
		bookDao.indexBook();
	}

	public List<Book> searchBook(String keyword, int firstResult, int maxResults)
	{
		return bookDao.searchBook(keyword, firstResult, maxResults);
	}
	
	public List<Book> searchBookByName(String keyword, int firstResult, int maxResults)
	{
		return bookDao.searchBookByName(keyword, firstResult, maxResults);
	}

	public List<Book> searchBookByAuthor(String keyword, int firstResult, int maxResults)
	{
		return bookDao.searchBookByAuthor(keyword, firstResult, maxResults);
	}

	public void indexBookComment()
	{
		bookCommentDao.indexBookComment();
	}

	public List<BookComment> searchBookComment(String keyword, int firstResult, int maxResults)
	{
		return bookCommentDao.searchBookComment(keyword, firstResult, maxResults);
	}

	public void indexChapter()
	{
		chapterDao.indexChapter();
	}

	public List<Chapter> searchChapter(String keyword, int firstResult, int maxResults)
	{
		return chapterDao.searchChapter(keyword, firstResult, maxResults);
	}

	public void indexErrorReport()
	{
		errorReportDao.indexErrorReport();
	}

	public List<ErrorReport> searchErrorReport(String keyword, int firstResult, int maxResults)
	{
		return errorReportDao.searchErrorReport(keyword, firstResult, maxResults);
	}

	public void indexGroup()
	{
		groupDao.indexGroup();
	}

	public List<Group> searchGroup(String keyword, int firstResult, int maxResults)
	{
		return groupDao.searchGroup(keyword, firstResult, maxResults);
	}

	public void indexGroupTopic()
	{
		groupTopicDao.indexGroupTopic();
	}

	public List<GroupTopic> searchGroupTopic(String keyword, int firstResult, int maxResults)
	{
		return groupTopicDao.searchGroupTopic(keyword, firstResult, maxResults);
	}

	public void indexGroupTopicComment()
	{
		groupTopicCommentDao.indexGroupTopicComment();
	}

	public List<GroupTopicComment> searchGroupTopicComment(String keyword, int firstResult, int maxResults)
	{
		return groupTopicCommentDao.searchGroupTopicComment(keyword, firstResult, maxResults);
	}

	public void indexMember()
	{
		memberDao.indexMember();
	}

	public List<Member> searchMember(String keyword, int firstResult, int maxResults)
	{
		return memberDao.searchMember(keyword, firstResult, maxResults);
	}

	public void indexMessage()
	{
		messageDao.indexMessage();
	}

	public List<Message> searchMessage(String keyword, int firstResult, int maxResults)
	{
		return messageDao.searchMessage(keyword, firstResult, maxResults);
	}
}
